﻿@page "/categories"
@inherits BaseCategoryPage

<PageContainer Title="Categories" PageTitle="@Title">
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>
                <a href="">
                    <MdiIcon Type="@IconNames.Home" />
                    <span>Home</span>
                </a>
            </BreadcrumbItem>
            <BreadcrumbItem>
                <span>
                    <MdiIcon Type="@IconNames.Category" />
                    <span>Categories</span>
                </span>
            </BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <ChildContent>
        <Loader OnLoad="@OnLoad" @ref="loader">
            <div>
                <Tree DataSource="Data.Root.Children.Values"
                      TitleExpression="x=>((CategoryTree.CategoryTreeNode)x.DataItem).Category.OneNameOrDefault()"
                      ChildrenExpression="x=>((CategoryTree.CategoryTreeNode)x.DataItem).Children.Values">
                    <TitleIconTemplate>
                        <MdiIcon Type="@IconNames.Category" />
                    </TitleIconTemplate>
                    <TitleTemplate>
                        <a style="font-size: 18px;" class="m-1" href="@UrlGenerator.Category(((CategoryTree.CategoryTreeNode)context.DataItem).Category)">@context.Title</a>
                    </TitleTemplate>
                </Tree>
            </div>
        </Loader>
    </ChildContent>
</PageContainer>

@code {
    private CategoryTree Data;

    private List<TreeNode> TreeNodes { get; set; } = new List<TreeNode>();

    private Loader loader;

    private async Task OnLoad()
    {
        Data = await Service.PostService.GetCategories();
    }
}
